package com.pms.mapper;

import com.github.pagehelper.Page;
import com.pms.dto.BuildingPageQueryDTO;
import com.pms.entity.Building;
import com.pms.entity.Community;
import com.pms.vo.BuildingPageQueryVO;
import com.pms.vo.BuildingSelectVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BuildingMapper {
    /**
     * 根据社区和楼栋编号查询记录
     * @param communityId
     * @param number
     * @return
     */
    @Select("select * from building where number = #{number} and community_id=#{communityId}")
    Building getByIdAndNumber(Integer communityId,String number);

    /**
     * 插入楼栋信息
     * @param building
     */
    @Insert("insert into building(community_id, number, status_id, owner_id, update_date) " +
            "values(#{communityId},#{number},#{statusId},#{ownerId},#{updateDate}) ")
    void insert(Building building);

    /**
     * 楼栋分页查询
     * @param buildingPageQueryDTO
     * @return
     */
    Page<BuildingPageQueryVO> pageQuery(BuildingPageQueryDTO buildingPageQueryDTO);

    /**
     * 根据社区id删除对应楼栋信息
     * @param id
     */
    @Delete("delete from building where community_id=#{id}")
    void deleteByCommunity(Integer id);

    /**
     * 删除楼栋
     * @param id
     */
    @Delete("delete from building where id=#{id}")
    void delete(Integer id);

    /**
     * 修改楼栋信息
     * @param building
     */
    void update(Building building);

    /**
     * 根据id查找楼栋信息
     * @param id
     * @return
     */
    @Select("select * from building where id=#{id}")
    Building getById(Integer id);

    /**
     * 根据id查找多个楼栋信息
     * @param buildingId
     * @return
     */
    @Select("select * from building where id=#{buildingId}")
    List<Building> getById2(Integer buildingId);

    /**
     * 根据业主id查找多个楼栋信息
     * @param id
     * @return
     */
    @Select("select * from building where owner_id=#{id}")
    List<Building> getByOwnerId(Integer id);

    /**
     * 根据小区名和楼栋号查询楼栋信息
     * @param communityName
     * @param buildingNumber
     * @return
     */
    Building getByCommunityNameAndBuildingNumber(String communityName, String buildingNumber);

    /**
     * 根据小区id获取楼栋列表
     * @param communityId
     * @return
     */
    @Select("select id,number from building where community_id=#{communityId}")
    List<BuildingSelectVO> getByCommunityId(Integer communityId);

    /**
     * 统计总数
     * @return
     */
    @Select("select count(*) from building")
    Integer count();

}
